package br.com.ngame;

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;

import br.com.ngame.core.GameCore;
import br.com.ngame.core.GameCoreListener;
import br.com.ngame.device.AppletVideoDevice;
import br.com.ngame.device.BasicAudioDevice;
import br.com.ngame.device.BasicInputDevice;
import br.com.ngame.device.VideoDevice;
import br.com.ngame.manager.AppletImageManager;
import br.com.ngame.manager.AppletSoundManager;

public abstract class AppletGame extends Applet implements GameCoreListener
{
	private static final long serialVersionUID = 1L;
	private GameCore game;
	private VideoDevice videoDevice;

	public void init()
	{
		log("APPLET INI >");
		videoDevice = new AppletVideoDevice(this);
		game = new GameCore(this);
		game.setVideoDevice( videoDevice );
		game.setAudioDevice( new BasicAudioDevice() );
		game.setInputDevice( new BasicInputDevice(this) );
		game.setImageManager( new AppletImageManager(this) );
		game.setSoundManager( new AppletSoundManager(this) );
		log("APPLET INI <");
	}
    
    protected GameCore getGame()
    {
    	return game;
    }
    
    public void start()
    {
    	log("APPLET START");
    	Thread gameThread = new Thread(game);
    	gameThread.setPriority(Thread.MAX_PRIORITY);
    	gameThread.start();
    }

    public void stop()
    {
    	log("APPLET STOP (send Terminate to GameCore)");
    	game.Terminate();
    }

    public void update(Graphics g)
    {
        paint(g);
    }

    public void paint(Graphics g)
    {
    	Graphics2D g2 = (Graphics2D)g;
        g2.drawImage(videoDevice.getScreenImage(), 0,0, this);
    }
    
    public void log(String msg)
    {
    	System.out.println(msg);
    }
    
    public void setup()
    {
    	// personalizado nas classes filhas
    }

    public void cleanup()
    {
    	// personalizado nas classes filhas    	
    }

	public void enterMenu()
	{
//		 personalizado nas classes filhas
	}

	public void enterPause()
	{
//		 personalizado nas classes filhas
	}

	public void exitMenu()
	{
//		 personalizado nas classes filhas
	}

	public void exitPause()
	{
//		 personalizado nas classes filhas
	}
}